﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AteneoLibriBusinessLogic.Entities;

namespace AteneoLibri
{
    public partial class RegistrationEnd : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (User.Identity.Name.Equals(System.Configuration.ConfigurationManager.AppSettings["AdminName"]))
                {
                    Page.MasterPageFile = "~/BackEnd/BackEndMasterPage.Master";
                }
                else
                {
                    Page.MasterPageFile = "~/Account/NewAccountMasterPage.Master";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string idUser = Request.QueryString["UserId"];
            bool result = false;
            if (idUser != null && idUser != "")
            {
                using (wsAteneoLibri.AteneoLibriServiceClient service = new wsAteneoLibri.AteneoLibriServiceClient())
                {
                    User user = service.getUserById(new Guid(idUser));
                    user.VerifyRegistration = true;

                    result = service.updateUser(user);
                    if (result)
                    {
                        pnlRegistrationSuccessfullyCompleted.Visible = true;
                    }
                    else
                    {
                        pnlRegistrationError.Visible = true;
                    }
                }
            }
        }
    }
}